package cn.wetcland.thread;

import cn.TCSP;
import cn.util.TCUtil;
import cn.wetcland.pojo.WetclandPlayer;
import com.gmail.filoghost.holographicdisplays.api.Hologram;
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

public class HologramThread {
    private Hologram hologram;
    public HologramThread(Player player) {
        this.hologram = HologramsAPI.createHologram(TCSP.getTcsp(), player.getEyeLocation().add(0.0D, 0.8D + 1 * 0.2D, 0.0D));
        WetclandPlayer one = TCUtil.getAttrPlayer(player.getName());
        String title = one.getTitle() == null ? "" : "§b" + one.getTitle() + "";
        hologram.appendTextLine("§d[" + TCUtil.getStringLevel(one.getLevel()) + "]  " + title);
        Bukkit.getScheduler().runTaskTimer(TCSP.getTcsp(), () -> {
            if (player.isOnline()) {
                hologram.clearLines();
                hologram.delete();
                this.hologram = HologramsAPI.createHologram(TCSP.getTcsp(), player.getEyeLocation().add(0.0D, 0.8D + 1 * 0.2D, 0.0D));
                this.hologram.appendTextLine("§d[" + TCUtil.getStringLevel(one.getLevel()) + "]  " + title);
            }
        }, 0, 0);
    }

    public Hologram getHologram() {
        return hologram;
    }

    public void setHologram(Hologram hologram) {
        this.hologram = hologram;
    }
}
